package com.lanmon.sqlite;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class SqliteConnection {
	
	private SqliteConnection() {
	}
	
	private static SqliteConnection INSTANCE = new SqliteConnection();
	
	/**
	 * 单例获取本类对象
	 * 
	 * @return
	 */
	public static SqliteConnection getInstance() {
		return INSTANCE;
	}
	
	/**
	 * 获取数据库连接
	 * 
	 * @return
	 */
	public static Connection getConnection() {
		try {
			return DriverManager.getConnection("jdbc:sqlite:exams.db");
		}
		catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static void close(Connection con) {
		try {
			if (con != null && !con.isClosed()) {
				con.close();
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
